package com.blunka.framework.client.db.druid.service;

import java.sql.SQLException;
import java.util.List;

import com.blunka.framework.client.db.druid.dbutils.IServiceDbHelper;
import com.blunka.framework.client.db.entity.BatchSqlEntity;
import com.blunka.framework.client.ui.entity.BlkTableMetaData;;

public interface ISQLService {

	/**
	 * 获取业务建模数据版本
	 * @return
	 */
	public String getDBVersion();

	/**
	 * 获取数据库地址
	 * @return
	 */
	public String getDBServerIP();
	
	/**
	 * 获取数据库名称
	 * @return
	 */
	public String getDBServerName();
	
	/**
	 * 获取数据库操作工具
	 * @return
	 */
	public IServiceDbHelper getDBUtils();

	/**
	 * 初始化远程数据库
	 * @throws Exception
	 */
	public void initServerDB()throws Exception;

	/**
	 * 查询数据结合
	 * @return
	 * @throws Exception
	 */
	public List<BlkTableMetaData> queryAllNode()throws Exception;

	/**
	 * 插入新节点，并且返回插入的节点内容
	 * @param node
	 * @return
	 */
	public BlkTableMetaData insertNode(BlkTableMetaData node)throws Exception;
	
	/**
	 * 插入新节点，并且返回插入的节点内容
	 * @param node
	 * @return
	 */
	public BlkTableMetaData insertNodeNoNewId(BlkTableMetaData node)throws Exception;
	
	/**
	 * 获取插入新节点sql
	 * @param node
	 * @return
	 * @throws Exception
	 */
	public BatchSqlEntity getinsertNodeNoNewIdSql(BlkTableMetaData node) throws Exception;

	/**
	 * 更新节点
	 * @param node
	 * @return
	 * @throws Exception
	 */
	public BlkTableMetaData updateNode(BlkTableMetaData node) throws Exception;

	/**
	 * 删除节点
	 * @param node
	 * @return
	 * @throws Exception
	 */
	public BlkTableMetaData deleteNode(BlkTableMetaData node) throws Exception;
	
	/**
	 * 新建表，只存储业务模型数据
	 * @param node
	 * @return
	 * @throws Exception
	 */
	public BlkTableMetaData insertTableNodeModel(BlkTableMetaData node) throws Exception;

	/**
	 * 新建表
	 * @param node
	 * @return
	 * @throws Exception
	 */
	public BlkTableMetaData insertTableNode(BlkTableMetaData node)throws Exception;
	
	/**
	 * 获取插入表或视图节点sql
	 * @param node
	 * @return
	 * @throws Exception
	 */
	public BatchSqlEntity getInsertTableNodeSql(BlkTableMetaData node) throws Exception;
	
	/**
	 * 新建表
	 * @param node
	 * @return
	 * @throws Exception
	 */
	public BlkTableMetaData insertTableNodeNoNewId(BlkTableMetaData node)throws Exception;
	
	/**
	 * 更新表，只更新业务数据
	 * @param node
	 * @return
	 * @throws Exception
	 */
	public BlkTableMetaData updateTableNodeModel(BlkTableMetaData node)throws Exception;

	/**
	 * 更新表
	 * @param node
	 * @return
	 * @throws Exception
	 */
	public BlkTableMetaData updateTableNode(BlkTableMetaData node)throws Exception;
	
	/**
	 * 删除表,只删除业务数据
	 * @param node
	 * @return
	 * @throws Exception
	 */
	public BlkTableMetaData	deleteTableNodeModel(BlkTableMetaData node)throws Exception;

	/**
	 * 删除表
	 * @param node
	 * @return
	 * @throws Exception
	 */
	public BlkTableMetaData	deleteTableNode(BlkTableMetaData node)throws Exception;
	
	/**
	 * 插入字段,只插入业务数据
	 * @param node 新节点
	 * @param table 所属表名
	 * @return
	 * @throws Exception
	 */
	public BlkTableMetaData insertFieldModel(BlkTableMetaData newBlkModel, BlkTableMetaData parentBlkModel)throws Exception;

	/**
	 * 插入字段
	 * @param node 新节点
	 * @param table 所属表名
	 * @return
	 * @throws Exception
	 */
	public BlkTableMetaData insertField(BlkTableMetaData newBlkModel,BlkTableMetaData parentBlkModel)throws Exception;
	
	/**
	 * 获取插入字段sql
	 * @param newBlkModel
	 * @return
	 * @throws Exception
	 */
	public BatchSqlEntity getInsertFieldSql(BlkTableMetaData newBlkModel)throws Exception;
	
	/**
	 * 插入字段
	 * @param newBlkModel
	 * @return
	 * @throws Exception
	 */
	public BlkTableMetaData insertField(BlkTableMetaData newBlkModel)throws Exception;
	
	/**
	 * 插入字段,直插入业务数据
	 * @param newBlkModel 新字段
	 * @param oldBlkModel 旧字段
	 * @param parentBlkModel 父节点
	 * @return
	 * @throws Exception
	 */
	public BlkTableMetaData updateFieldModel(BlkTableMetaData newBlkModel,BlkTableMetaData parentBlkModel) throws Exception;

	/**
	 * 插入字段
	 * @param newBlkModel 新字段
	 * @param parentBlkModel 父节点
	 * @return
	 * @throws Exception
	 */
	public BlkTableMetaData updateField(BlkTableMetaData newBlkModel,BlkTableMetaData parentBlkModel)throws Exception;
	
	/**
	 * 删除字段,只删除业务数据
	 * @param newBlkModel
	 * @param parentBlkModel
	 * @return
	 * @throws Exception
	 */
	public BlkTableMetaData deleteFieldModel(BlkTableMetaData newBlkModel,BlkTableMetaData parentBlkModel)throws Exception;

	/**
	 * 删除字段
	 * @param newBlkModel
	 * @param parentBlkModel
	 * @return
	 * @throws Exception
	 */
	public BlkTableMetaData deleteField(BlkTableMetaData newBlkModel,BlkTableMetaData parentBlkModel)throws Exception;


	/**
	 * 查询表或者是否是否已经存在
	 * @param model
	 * @return
	 * @throws SQLException
	 */
	public boolean queryTableOrViewExists(BlkTableMetaData model)throws SQLException;

	/**
	 * 判断modelname业务模型名称在节点model的子节点中是否存在
	 * @param model 当前节点
	 * @param modelname 子节点名称
	 * @return
	 * @throws SQLException
	 */
	public boolean queryTableOrViewFieldExists(BlkTableMetaData model,String tablename)throws SQLException;
	
	/**
	 * 判断modelname业务模型名称在节点model的子节点中是否存在
	 * @param model
	 * @param modelname
	 * @return
	 * @throws SQLException
	 */
	public boolean queryModelNodeExists(BlkTableMetaData model,String modelname)throws SQLException;

	/**
	 * 查询表字段索引是否存在
	 * @param table_fieldindex_name
	 * @return
	 * @throws SQLException
	 */
	public boolean queryIndexExists(String table_fieldindex_name,String tablename) throws SQLException;

	/**
	 * 删除数据库选中的节点及子节点
	 * @param selModel
	 * @param parentModel
	 * @throws Exception
	 */
	public void batchModelNode(List<BatchSqlEntity> sqlList)throws Exception;
}
